/**   
 * @Title: HeMaiListCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.hemai 
 * @Description: TODO(获取合买列表通讯接口) 
 * @author: Billy Qigs@500wan.com   
 * @date: 2011-11-29 下午12:12:02  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.hemai;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Key;
import com.esun.model.HeMaiListInfo;
import com.esun.model.UserInfo;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: HeMaiListCommunicater
 * @Description: (获取合买列表通讯接口)
 * @author: Billy Qigs@500wan.com
 * @date: 2011-11-29 下午12:12:02
 * 
 */
public class HeMaiListCommunicater extends ServerCommunicater {

	private String serverMsg = "";
	private ArrayList<HeMaiListInfo> arrayHeMaiList = new ArrayList<HeMaiListInfo>();

	public boolean isGetHemaiListSucceed(String expect, String lotId, String sortField, String sortCode, String pageSize, String pageNo) throws ClientProtocolException, IOException,
			ParserConfigurationException, SAXException {

		boolean isSucceed = false;

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_GET_HEMAI_LIST_2));
		list.add(mapItem(BussinessCode.PASER_CK, UserInfo.getUserInfo().getUserSession()));
		list.add(mapItem(Key.KEY_EXPECT, expect));
		list.add(mapItem(Key.KEY_LOTID, lotId));
		list.add(mapItem(Key.KEY_SORTFIELD, sortField));
		list.add(mapItem(Key.KEY_SORTORDER, sortCode));
		list.add(mapItem(Key.KEY_PAGESIZE, pageSize));
		list.add(mapItem(Key.KEY_PAGENO, pageNo));
		// 写入服务器返回信息
		super.getServerResponse(list, true);
		setServerMessage(super.getServerMsg());
		if (super.getState() == 100) {
			isSucceed = true;
			organizeData(super.getListResult());
		} else {
			isSucceed = false;
		}
		return isSucceed;
	}

	private void organizeData(ArrayList<Hashtable<String, String>> list) {

		arrayHeMaiList.clear();

		for (int i = 0; i < list.size(); i++) {

			HeMaiListInfo heMaiList = new HeMaiListInfo();
			Hashtable<String, String> hash_temp = new Hashtable<String, String>();
			hash_temp = list.get(i);

			heMaiList.setID(hash_temp.get(Key.KEY_ID));
			heMaiList.setAllMoney(hash_temp.get(Key.KEY_ALLMONEY));
			heMaiList.setProID(hash_temp.get(Key.KEY_PROID));
			heMaiList.setPlayType(hash_temp.get(Key.KEY_PLAYTYPE));
			heMaiList.setUserName(hash_temp.get(Key.KEY_USERNAME));
			heMaiList.setZhanJi(hash_temp.get(Key.KEY_ZHANJI));
			heMaiList.setJinDu(hash_temp.get(Key.KEY_RENQI));
			heMaiList.setAllNumber(hash_temp.get(Key.KEY_ANUMBER));
			heMaiList.setOneMoney(hash_temp.get(Key.KEY_ONEMONEY));
			heMaiList.setBuyNumber(hash_temp.get(Key.KEY_HNUMBER));
			heMaiList.setOrderOrNot(hash_temp.get(Key.KEY_SETORDER));

			arrayHeMaiList.add(heMaiList);
		}

	}

	public ArrayList<HeMaiListInfo> getHeMainList() {
		return this.arrayHeMaiList;
	}

	private void setServerMessage(String str) {
		serverMsg = str;
	}

	public String getServerMsg() {
		return serverMsg;
	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}

}
